from google.appengine.ext import bulkload
from google.appengine.api import datastore_types
from google.appengine.ext import search
from google.appengine.api import urlfetch
from pyth.inventionmodels import *

base = "http://www1.cs.columbia.edu/~ollie/CraftComputing/"

class ImageLoader(bulkload.Loader):
  def __init__(self):
    # Our 'Person' entity contains a name string and an email
    #print 'here'
    bulkload.Loader.__init__(self, 'Image', 
                         [('path', str)])

  def HandleEntity(self, entity):
    image = Image()
    image.path = entity['path']
    try:
        image.im = datastore_types.Blob(urlfetch.Fetch(base+entity['path']).content)
    except:
        image.path = 'failed to load ' + entity['path']
    image.put()
            
    return None

if __name__ == '__main__':
  bulkload.main(ImageLoader())